'use strict';
module.exports = app => {
    const { INTEGER, STRING, TEXT } = app.Sequelize;
    const Product = app.model.define(
      'Product',
          {
              id: {type: INTEGER, primaryKey: true, autoIncrement: true},
              image: STRING,
              name: STRING,
              status: INTEGER,
              count: INTEGER,
              max_count: INTEGER,
          },
          {
              tableName: 'product',
              timestamps: true, // 启用时间戳(createdAt, updatedAt)
          }
    );
    Product.associate = function() {
        app.model.Product.hasMany(app.model.LotteryRecord, {
            foreignKey: 'product_id',
            targetKey: 'id',
            as: 'lotteryRecordList',
        });
        app.model.Product.hasMany(app.model.User, {
            foreignKey: 'product_id',
            targetKey: 'id',
            as: 'userList',
        });
    }
    return Product;
};
